package com.company.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.company.project.common.aop.annotation.LogAnnotation;
import com.company.project.common.utils.Func;
import com.company.project.entity.*;
import com.company.project.service.HttpSessionService;
import com.company.project.service.RoleService;
import com.company.project.vo.req.TSeatsEntityOperationReqVO;
import io.swagger.annotations.Api;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.Date;
import java.util.List;
import com.company.project.common.utils.DataResult;

import com.company.project.service.TSeatsService;

import javax.annotation.Resource;

/**
 * 
 *
 * @author wenbin
 * @email *****@mail.com
 * @date 2023-10-12 08:44:53
 */
@Api("坐席管理")
@Controller
@RequestMapping("/")
public class TSeatsController {
    @Autowired
    private TSeatsService tSeatsService;

    @ApiOperation(value = "新增")
    @PostMapping("tSeats/add")
    @LogAnnotation(title = "坐席", action = "新增")
    @RequiresPermissions("tSeats:add")
    @ResponseBody
    public DataResult add(@RequestBody TSeatsEntityOperationReqVO tSeatsEntityOperationReqVO){
        return tSeatsService.addTSeats(tSeatsEntityOperationReqVO);
    }

    @ApiOperation(value = "删除")
    @LogAnnotation(title = "坐席", action = "删除")

    @DeleteMapping("tSeats/delete")
    @RequiresPermissions("tSeats:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        tSeatsService.deleteUser(ids);
        tSeatsService.removeByIds(ids);
        return DataResult.success();
    }
    @ApiOperation(value = "启用")
    @LogAnnotation(title = "坐席", action = "启用")
    @PostMapping("tSeats/sta")
    @ResponseBody
    public DataResult sta(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        tSeatsService.sta(ids);
        return DataResult.success();
    }
    @ApiOperation(value = "禁用")
    @LogAnnotation(title = "坐席", action = "禁用")

    @PostMapping("tSeats/nosta")
    @ResponseBody
    public DataResult nosta(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        tSeatsService.nosta(ids);
        return DataResult.success();
    }
    @ApiOperation(value = "更新")
    @LogAnnotation(title = "坐席", action = "更新")
    @PutMapping("tSeats/update")
    @RequiresPermissions("tSeats:update")
    @ResponseBody
    public DataResult update(@RequestBody TSeatsEntityOperationReqVO vo){

        return  tSeatsService.updateEntity(vo);
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("tSeats/listByPage")
    @LogAnnotation(title = "坐席", action = "查询分页数据")
    @RequiresPermissions("tSeats:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody TSeatsEntityOperationReqVO tSeats){
        Page page = new Page(tSeats.getPage(), tSeats.getLimit());
        LambdaQueryWrapper<TSeatsEntity> queryWrapper = Wrappers.lambdaQuery();
        //查询条件示例
        //queryWrapper.eq(TSeatsEntity::getId, tSeats.getId());
        IPage<TSeatsEntity> iPage = tSeatsService.pageData(page, tSeats);
        return DataResult.success(iPage);
    }
    @GetMapping("tSeats/infoData")
    @LogAnnotation(title = "坐席", action = "infoData")

    @ResponseBody
    public DataResult infoData(){
        return tSeatsService.infoData();
    }

    @ApiOperation(value = "更新分钟数")
    @LogAnnotation(title = "坐席", action = "更新分钟数")
    @PutMapping("tSeats/updateFzs")
    //@RequiresPermissions("tSeats:updateFzs")
    @ResponseBody
    public DataResult updateFzs(@RequestBody TSeatsEntityOperationReqVO vo){
        if(Func.isEmpty(vo.getFzs())){
            return DataResult.fail("分钟数不能为空");
        }
//        if(Func.isBlank(vo.getSmscode())){
//            return DataResult.fail("验证码不能为空");
//        }
        return tSeatsService.updateFzs(vo);
    }

    @ApiOperation(value = "续费")
    @PutMapping("tSeats/updateXf")
    @LogAnnotation(title = "坐席", action = "续费")
    @ResponseBody
    public DataResult updateXf(@RequestBody TSeatsEntityOperationReqVO vo){
        if(Func.isBlank(vo.getYgtc())){
            return DataResult.fail("套餐不能为空");
        }
        if(Func.isBlank(vo.getXfyf())){
            return DataResult.fail("月份不能为空");
        }
        return tSeatsService.updateXf(vo);
    }

    @ApiOperation(value = "外呼")
    @PostMapping("tSeats/outbound")
    @LogAnnotation(title = "坐席", action = "外呼")
    @ResponseBody
    public DataResult outbound(@RequestBody TSeatsEntityOperationReqVO vo){
        if(Func.isBlank(vo.getPhoneWH())){
            return DataResult.fail("手机号不能为空");
        }
        return tSeatsService.outbound(vo);
    }

    /**
     * 跳转到页面
     */
    @GetMapping("/index/waihu")
    public String tMiddlenum() {
        return "waihuGL/waihu/call";
    }


    @PostMapping("tSeats/callbak/dxline")
    @LogAnnotation(title = "坐席", action = "回调")
    public DataResult notifyurl(@RequestBody CallbackEntityVo1 vo) {
        tSeatsService.notifyurl1(vo);
        return DataResult.success();
    }

    @PostMapping("tSeats/callbak/dyline")
    @LogAnnotation(title = "坐席", action = "回调")
    public DataResult dyline(@RequestBody CallbackEntityVo2 vo) {
        tSeatsService.dyline(vo);
        return DataResult.success("",0000);
    }
}
